using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Text;
using HtmlAgilityPack;
using OGS.Contracts;

namespace OGS.Utility
{
    /// <summary>
    /// This class is for finding Areas by post codes
    /// </summary>
    public class PostCodeHelper
    {

		/// <summary>
        /// Get Areas by Post Code
        /// </summary>
        /// <param name="PostCode"></param>
        /// <returns></returns>
        public static List<Area> GetAreas(string PostCode)
        {
            string strHTML = string.Empty;

            //POST REQUEST TO GET AREA BY POST CODE
            using (var wb = new WebClient())
            {
                var data = new NameValueCollection();
                data["code"] = PostCode;
                data["p"] = "2";
                
                var response = wb.UploadValues("http://www.prokerala.com/general/pin-codes/", "POST", data);
                strHTML = System.Text.Encoding.UTF8.GetString(response);
                strHTML = strHTML.Replace("\r", "").Replace("\n", "").Replace("\t", "");
            }


            //LOAD HTML DOC AND FIND THE RESULT TABLE
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(strHTML);
            HtmlNode table = doc.DocumentNode.SelectSingleNode("//*[contains(@class, 'table-striped')]");
            List<Area> lstAreas = new List<Area>();

            if (table != null)
            {
                //LOOP THROUGH THE TABLE RESULTS
                for (int index = 1; index < table.ChildNodes.Count; index++)
                {
                    var row = table.ChildNodes[index];
                    if (row.ChildNodes.Count >= 3)
                    {
                        Area objArea = new Area();
                        objArea.Name = Helper.RemoveHTMLTags(row.ChildNodes[0].InnerHtml.Replace("S.O", "").Replace("B.O", ""));
                        objArea.District = Helper.RemoveHTMLTags(row.ChildNodes[2].InnerHtml);
                        lstAreas.Add(objArea);
                    }

                }
            }

            // ARRANGE THE AREAS ORDER BY NAME
            if (lstAreas.Count > 0)
            {
                lstAreas = lstAreas.OrderBy(a => a.Name).ToList();
            }

            return lstAreas;
        }
    

        /// <summary>
        /// Get Areas by Post Code
        /// </summary>
        /// <param name="PostCode"></param>
        /// <returns></returns>
        public static List<Area> GetAreasOld(string PostCode)
        {
            string strHTML = string.Empty;

            //POST REQUEST TO GET AREA BY POST CODE
            using (var wb = new WebClient())
            {
                var data = new NameValueCollection();
                data["__EVENTARGUMENT"] = "";
                data["__EVENTTARGET"] = "";
                data["__EVENTVALIDATION"] = "f//yOAZXO7w9l/ShYAhSNFjpnLMsvSQ9DH/64MromkpPzFYmbV+GZ4klkg7VpJvZbuu2ipnHlHdof8tz0MpXP0OIQURdLYJK5YG5CRAmQprHzUiHpyEv4NIwH92azgy5/TvywsXbgN4x+Z1BORDVoCrBnmsw7jnZO1flYunBiFO8w5SHk+946l4EUFySAjlpLtYTHl0aViZy+6Nf6gpFj7nUgatdLBJJrtjoj5BrtKw61mr6b+ytwCllN8SJ+tjkYIpGzrpUjQAZ7Foq43aA6XlvolgG+SGNDIG2VhKmq1n2X1nIgGYrvP7R8cmttrN4MYwVbOivYmPlDro9Qs+NTwolV8lc8DRTLgCIOC/7PcjJgRkGh7Axi1yqqi6wgmFZzwhpUtqA3VFAvCv1wG0NjNr73lQkNlGQMtSZo24LnWN25RNWip+OT6tzj/Qzg8oWoyvj7kzUjGW8SJFVR8gA7bVdWag28jPggSrB3nH3uGHgYOU+G8D4jrHDvbjRvbuCJT8oqLMEWIPxHtKzW16HBIOwLvP4ccjY1rS1Q0QX0Rujq+5ExNXtLqX+eM9u7qBNpoShJdcP06IyrgNQ6uSWr7nIf+PdtgIqiXs/CGHRUMbqBdpeuIXVEdvpjofQmdQ3qaJlXe4dGMyYdvUDmHsDP856W+qUIdPnh4Pf79FIVqGox1lpKbagWzQYbg82Pswh4MMxr7UL8S1u2NsnQrFIyoe/9MMvuIPZkL+frs7DU6EpejpwX+pkxsHgsqKobwEuU4yhQdMkq3i3xD58FqCnmyKGTggGlwr5o3pFfqkvGQ5rBqL7ns6HyyNKP0ViWINiJFDvWPXX0dNtneAsvioasSfsVxmpfQApbvK+vEZU6VlakMbuhe2UIlUJU6k2INeI1K1s1gCQPg0GipGkgIosv7eU/jrGwV/DgDDj0pIw3+YmWliZqO3cYiSpaD/+Lns1M2sSWr2mrVrFhmfXFZ4Qn8TSxEW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+W8nkLVh+XLx1xSXClyieIqS4arXL9aHVMmvJfWuUmFP6lIn5kOtrQ6Z84fhS4PBlsCggYgMdOkZ6lRUF6JgY+rXz32UOkyDQXIPKHGWXYSbAQx0QFkjboMT/oHrT7TmXBiGdp+s0b4zsOQHHkq5LrdWSBsTLYG/0d/O42S0Z475YIIzoVcll39CaRa3BjitESe2Vwmb0EkpnGUhVDE721LW4uKB35FMcwEhdvokbTQfatnFyWsbtAveZgCqm5qwqMdCRmalcwcXlQETyz/O5Tk4xU+yK472MOZI05wDbRMirwjVs6fqy8byN/8OQaSDvx+tg2NbCezBelgfytOM2teiw5fwzpiZacHCO6g9QLS+N4fsioFerwi5fBhd7cPnjFPxqniz/HvuRskH7SXATavMoRb/1pugsNwooUHBh/g==";
                data["__VIEWSTATEENCRYPTED"] = "";
                data["ddl_dist"] = "0";
                data["ddl_state"] = "1";
                data["hdn_tabchoice"] = "1";
                data["search_on"] = "Search";
                data["txt_dist_on"] = "";
                data["txt_offname"] = PostCode;
                data["txt_stateon"] = "";

                var response = wb.UploadValues("http://utilities.cept.gov.in/pinsearch/pinsearch.aspx", "POST", data);
                strHTML = System.Text.Encoding.UTF8.GetString(response);
                strHTML = strHTML.Replace("\r", "").Replace("\n", "").Replace("\t", "");
            }


            //LOAD HTML DOC AND FIND THE RESULT TABLE
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(strHTML);
            HtmlNode table = doc.DocumentNode.SelectSingleNode("//*[contains(@id, 'gvw_offices')]");
            List<Area> lstAreas = new List<Area>();

            if (table != null)
            {
                //LOOP THROUGH THE TABLE RESULTS
                for (int index = 2; index < table.ChildNodes.Count; index++)
                {
                    var row = table.ChildNodes[index];
                    if (row.ChildNodes.Count >= 3)
                    {
                        Area objArea = new Area();
                        objArea.Name = Helper.RemoveHTMLTags(row.ChildNodes[1].InnerHtml.Replace("S.O", "").Replace("B.O", ""));
                        objArea.District = Helper.RemoveHTMLTags(row.ChildNodes[3].InnerHtml);
                        lstAreas.Add(objArea);
                    }

                }
            }

            // ARRANGE THE AREAS ORDER BY NAME
            if (lstAreas.Count > 0)
            {
                lstAreas = lstAreas.OrderBy(a => a.Name).ToList();
            }

            return lstAreas;
        }
    }
}
